<?php

/**
 * Yii Controller PostController
 *
 * @author luubk
 * @since Jan 15, 2013 - 1:10:27 PM
 */
class PostController extends BackController
{

    public $modelName = 'Post';

    public function init()
    {
        parent::init();
        $this->typeMyActiveForm = TRUE;
        $this->controllerMenu = array();

        $this->controllerMenu[] = array(
            'label' => Yii::t('post', 'Category'),
            'url' => $this->createUrl('category/index', array('lang' => $this->lang))
        );

        $this->controllerMenu[] = array(
            'label' => 'Danh sách bài viết',
            'url' => $this->createUrl('post/index', array('lang' => $this->lang))
        );
    }

    public function save($action = 'Create')
    {
        $this->model->setScenario('unni');
        $status = parent::save($action);
        if ($status)
        {
            if ($action == 'Create')
            {
                $this->model->created_at = time();
                $this->model->save();
            }
            if (isset($_POST['post_fb']))
            {
                $msg = $_POST['fb_msg'];
                $link = $this->model->getPublicUrl(TRUE);
                $picture = $this->model->getPublicPhoto(TRUE);
                $title = $_POST['fb_title'];
                $website = $_SERVER['HTTP_HOST'];
                $description = $_POST['fb_des'];
                //post bài lên facebook
                MyARContent::postFacebook($msg, $link, $picture, $title, $website, $description);
            }
        }
        return $status;
    }

    public function actionRenewToken()
    {
        Yii::import('application.extensions.facebook.Facebook');
        $fb = new Facebook(Yii::app()->params['facebook']); //Config
        print_r($fb->setExtendedAccessToken());
    }

}

/** 
* End file PostController
*/
